package com.usaas.search.interceptor.realnameauth;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RealNameAuthInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

//        //如果是白名单里的 不需要校验
//        if (AppApiFilter.appWhiteList.contains(request.getRequestURI())) {
//            return true;
//        }
//        if (!(handler instanceof HandlerMethod)) {
//            return true;
//        }
//        HandlerMethod handlerMethod = (HandlerMethod) handler;
//        // 获取方法上的自定义注解
//        RealNameAuth realNameAuth = handlerMethod.getMethodAnnotation(RealNameAuth.class);
//        if (realNameAuth == null) {
//            return true;
//        }
//        // 在请求处理之前执行
//        AppTokenComponent appTokenComponent = SpringUtils.getBean(AppTokenComponent.class);
//        // 校验是否实名
//        PlatUserDto userInfo = appTokenComponent.getUserInfo();
//        if (userInfo == null) {
//            ExceptionUtil.throwError("登录失效,请重新登录");
//        }
//
//        String realName = userInfo.getRealName();
//        String idcard = userInfo.getIdcard();
//        if (!StrUtil.isAllNotBlank(realName, idcard)) {
//            ExceptionUtil.throwError("尚未实名认证,请先实名");
//        }
        return true; // 返回true继续流程，false则结束流程
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        // 请求处理之后，渲染视图之前执行
        System.out.println("Post Handle");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        // 渲染视图之后执行
        System.out.println("After Completion");
    }
}
